var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), e = require("../../@babel/runtime/helpers/asyncToGenerator"), i = getApp(), a = require("../../utils/timeUtil.js"), r = require("../../http/activityApi.js");

Page({
    id: 0,
    timer: null,
    data: {
        systemInfo: i.data.systemInfo,
        inited: !1,
        seriesList: [],
        hasMore: !0
    },
    onLoad: function(t) {
        t.id && (this.id = t.id), this.loadData();
    },
    onShow: function() {
        this.startTimer();
    },
    onHide: function() {
        this.stopTimer();
    },
    onUnload: function() {
        this.stopTimer();
    },
    startTimer: function() {
        var t = this;
        this.stopTimer(), this.timer = setInterval(function() {
            t.ticket();
        }, 1e3);
    },
    stopTimer: function() {
        null != this.timer && (clearInterval(this.timer), this.timer = null);
    },
    ticket: function() {
        if (this.data.inited) {
            var t = this.data.startTime, e = this.data.endTime, i = new Date().getTime();
            if (i < t) {
                var a = this.parseTime(t - i);
                this.setData({
                    activityState: 1,
                    timeDesc: a[0] + "h：" + a[1] + "m：" + a[2] + "s"
                });
            } else if (i > e) this.setData({
                activityState: 3,
                timeDesc: null
            }); else {
                var r = this.parseTime(e - i);
                this.setData({
                    activityState: 2,
                    timeDesc: r[0] + "h：" + r[1] + "m：" + r[2] + "s"
                });
            }
        }
    },
    parseTime: function(t) {
        return [ Math.floor(t / 36e5), Math.floor(t % 36e5 / 6e4), Math.floor(t % 6e4 / 1e3) ];
    },
    openRuleOnTap: function() {
        this.setData({
            showRuleDialog: !0
        });
    },
    closeRuleOnTap: function() {
        this.setData({
            showRuleDialog: !1
        });
    },
    loadData: function() {
        var s = this;
        return e(t.default.mark(function e() {
            var n, o, l, m, u;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, i.showLoading(), t.next = 4, r.newUserHome(s.id);

                  case 4:
                    if (2 != (n = t.sent).data.status) {
                        t.next = 8;
                        break;
                    }
                    throw i.showAlert("提示", "活动已关闭"), new Error();

                  case 8:
                    o = a.timeStringToLong(n.data.startTime), l = a.timeStringToLong(n.data.endTime), 
                    new Date().getTime() >= o && o <= l && n.data.registerTimeLimit > 0 && (m = a.timeStringToLong(i.data.loginInfo.userInfo.createTime), 
                    u = m + 60 * n.data.registerTimeLimit * 60 * 1e3, 0 == n.data.memberActivityStatus && u < l && (l = u)), 
                    n.data.activityRule = n.data.activityRule.replace(/\<img/gi, '<img class="block"'), 
                    s.setData({
                        inited: !0,
                        title: n.data.activityTitle,
                        seriesList: n.data.activityProductVoList,
                        hasMore: !1,
                        rule: n.data.activityRule,
                        startTime: o,
                        endTime: l,
                        allowJoin: 0 == n.data.memberActivityStatus,
                        registerTimeLimit: n.data.registerTimeLimit,
                        photoMap: n.data.photoMap
                    }), s.ticket(), t.next = 20;
                    break;

                  case 17:
                    t.prev = 17, t.t0 = t.catch(0), console.log(t.t0);

                  case 20:
                    return t.prev = 20, wx.hideLoading(), t.finish(20);

                  case 23:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 0, 17, 20, 23 ] ]);
        }))();
    }
});